<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddFieldsToCustomerInfosTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('customer_infos', function (Blueprint $table) {
            $table->bigInteger('referee_id')->unsigned()->nullable()->comment('推荐人ID');
            $table->foreign('referee_id')->references('id')->on('users')->onDelete('restrict');
            $table->integer('clue_point')->default(0)->comment('留资获得积分数');
            $table->datetime('driver_at')->nullable()->comment('试驾时间');
            $table->integer('driver_point')->default(0)->comment('试驾获得积分数');
            $table->datetime('buy_car_at')->nullable()->comment('购车时间');
            $table->integer('buy_car_point')->default(0)->comment('购车获得积分数');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('customer_infos', function (Blueprint $table) {
            $table->dropForeign('referee_id');
            $table->dropColumn('referee_id');
            $table->dropColumn('clue_point');
            $table->dropColumn('driver_at');
            $table->dropColumn('driver_point');
            $table->dropColumn('buy_car_at');
            $table->dropColumn('buy_car_point');
        });
    }
}
